<%@ page language="java" import="java.util.*,com.beans.*,com.dao.*" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
%>
<!DOCTYPE HTML>
<html>
<head>
    <base href="<%=basePath%>">

    <title></title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">

    <link rel="stylesheet" type="text/css" href="css/edittable.css"  >
    <link rel="stylesheet" type="text/css" href="css/validate.css"  >
    <script src="js/jquery-1.8.0.js"></script>
</head>
	<script>
		//查看角色名是否重复
		function checkRoleNameOk(){
			var ok=true;
			
			$.ajax({
				type:"POST",
				url:"RoleServlet.do",
				data:{flog:"checkRoleNameOk",roleName:$("input[name=roleName]").val()},
				async:false,
				success:function(o){
					if(o=="0"){
						$("label").html("角色名已经被占用");
						ok=false;
					}
				}
			});
			return ok;
		}
		
		function checkKong(){
			if($("input[name=roleName]").val()==""){
				$("label").html("角色名不能为空");
				return false;
			}
			return true;
		}
		//清空
		function cleansp(){
			var sp=document.getElementsByTagName("label");
			for(var i=0;i<sp.length;i++){
				sp[i].innerHTML="";
			}
		}
		
		function tijiao(){
			cleansp();
			var fal=true;
			
			if(checkKong()==false){
				fal=false;
			}
			
			if(fal==true){
				return confirm("确认提交吗");
			}else{
				alert("有问题");
				return fal;
			}
		}
	</script>
	<%
		int roleId=Integer.parseInt(request.getParameter("id"));
		RoleDao dao=new RoleDao();
		RoleInfo roleInfo=dao.getRoleInfoById(roleId);
		pageContext.setAttribute("roleInfo", roleInfo);
	%>
	<script>
		$(function(){
			$("input[name=roleName]").val("${roleInfo.roleName}");
			$("textarea[name=des]").val("${roleInfo.des}");
		});
		
	</script>

<body>
	<div class ="div_title">
	    <div class="div_titlename"> <img src="images/san_jiao.gif" ><span>角色修改</span></div>
	</div>
	
	<form action="RoleServlet.do?flog=change" method="post" onsubmit="return tijiao()">
		<table class="edit_table">
			<input type="hidden" name="id" value="${roleInfo.id }"/>
		    <tr>
		        <td class="td_info">角色名称：</td>
		        <td class="td_input_short"><input type="text" name="roleName"></td>
		        <td><label class="validate_info" name="roleNamesp"></label></td>
		    </tr>
		    <tr>
		        <td class="td_info">角色描述：</td>
		        <td class="td_input_short"><textarea rows="4" cols="27" name="des" class="txtarea"></textarea></td>
		        <td></td>
		    </tr>
		    <tr>
		        <td class="td_info"></td>
		        <td>
		        	<input type="submit" value="提交" class="form_btn">
		        	<input type="reset" value="重置" class="form_btn" onclick="cleansp()"></td>
		        <td></td>
		    </tr>
		</table>
	</form>
	${msg }
</body>
</html>
